import { join } from 'path';
import { IMessage } from 'qq-guild-bot';
import { readYaml } from '../../../src/lib/tool';

export async function bq(e: { eventType: string; msg: IMessage }) {
  // 私聊禁用
  if (e.eventType === 'DIRECT_MESSAGE_CREATE') {
    return;
  }

  let bqPath = join(process.cwd(), '/plugins/biaoqing/resources/biaoqing/biaoqing.yaml');

  let bq = readYaml(bqPath);

  if ((bq ?? '') === '' || typeof bq === 'string') {
    return;
  }

  let list = Object.keys(bq);
  for (let item of list) {
    if (item === e.msg.content) {
      let message = {
        image: bq[item].image ? 'https://' + bq[item].image : undefined,
        content: bq[item].content ? bq[item].content : undefined,
        msg_id: e.msg.id
      };
      await client.messageApi.postMessage(e.msg.channel_id, message);

      return true;
    }
  }
}
